home *** CD-ROM | disk | FTP | other *** search
Wrap
function ballMove() { streaks._x = ball._x; streaks._y = ball._y; gameController(); if(getTimer() > this.collideTimer + collideTime) { colliding = false; } this._rotation += this.dw; this.vx *= DAMP; this.vy *= DAMP; this._x += this.vx; this._y += this.vy; if(this._x > RIGHT) { this._x = RIGHT; this.vx *= BOUNCE; Sound1.start(0,1); } else if(this._x < LEFT) { this._x = LEFT; this.vx *= BOUNCE; Sound1.start(0,1); } if(this._y > BOTTOM) { this._y = BOTTOM; this.vy *= BOUNCE; Sound1.start(0,1); } else if(this._y < TOP) { this._y = TOP; this.vy *= BOUNCE; Sound1.start(0,1); } if(ball.hitTest(goalOpponent.hit)) { opponentsGoalDisplay.bounceIn(0); centerBall(); scoreOpponent++; scoreBoardOpponent.scoreText.text = scoreOpponent; if(scoreOpponent == winningScore) { gotoAndStop("game over"); play(); } } else if(ball.hitTest(goalPlayer.hit)) { playersGoalDisplay.bounceIn(0); centerBall(); scorePlayer++; scoreBoardPlayer.scoreText.text = scorePlayer; if(scorePlayer == winningScore) { gotoAndStop("game over"); play(); } } } function centerBall() { ball._visible = true; delete ball.onEnterFrame; ball._x = 168; ball._y = 244; } function restart() { centerBall(); var _loc1_ = new mx.transitions.Tween(ball,"_xscale",mx.transitions.easing.Bounce.easeOut,500,100,1.5,true); var _loc2_ = new mx.transitions.Tween(ball,"_yscale",mx.transitions.easing.Bounce.easeOut,500,100,1.5,true); _loc1_.onMotionFinished = function() { ball.dw = 0; ball.vx = rand((- VMAX) / 2,VMAX / 2); if(Math.random() > 0.5) { ball.vy = - VMAX; } else { ball.vy = VMAX; } ball.onEnterFrame = ballMove; }; } function gameController() { controls(); moveOpponent(); } function controls() { if(Key.isDown(39)) { players._x = Math.min(players._x + MOVERATE,playersRightBoundary); } else if(Key.isDown(37)) { players._x = Math.max(players._x - MOVERATE,playersLeftBoundary); } } function moveOpponent() { ballRelative = ball._y - opponents._y; if(ball.vy < 0) { if(ballRelative > rowsOpponent[0][0]._y) { activeRow = 0; } else if(ballRelative > rowsOpponent[1][0]._y) { activeRow = 1; } else if(ballRelative > rowsOpponent[2][0]._y) { activeRow = 2; } else { activeRow = 3; } } else if(ballRelative < rowsOpponent[3][0]._y) { activeRow = 3; } else if(ballRelative < rowsOpponent[2][0]._y) { activeRow = 2; } else if(ballRelative < rowsOpponent[1][0]._y) { activeRow = 1; } else { activeRow = 0; } column = 0; distance = Stage.width; i = 0; while(i < rowsOpponent[activeRow].length) { testDistance = Math.abs(ball._x - rowsOpponent[activeRow][i]._x - opponents._x); if(testDistance < distance) { column = i; distance = testDistance; } i++; } rowsOpponent[activeRow][column].tint = 100; difference = ball._x - rowsOpponent[activeRow][column]._x - opponents._x; if(difference >= OPPONENTMOVERATE) { opponents._x = Math.min(opponents._x + OPPONENTMOVERATE,opponentsRightBoundary); } else if(difference <= - OPPONENTMOVERATE) { opponents._x = Math.max(opponents._x - OPPONENTMOVERATE,opponentsLeftBoundary); } if(!collisions()) { collisionsPlayer(); } } function aimOpponentGoal() { var _loc2_ = goalOpponent._x - ball._x; var _loc1_ = goalOpponent._y - ball._y; angle = Math.atan2(_loc1_,_loc2_); streaks._rotation = (angle + 3.141592653589793) * 180 / 3.141592653589793; streaks.play(); stick._rotation = angle * 180 / 3.141592653589793; return angle; } function aimOpponent(target) { var _loc2_ = target._x + opponents._x - ball._x; var _loc1_ = target._y + opponents._y - ball._y; angle = Math.atan2(_loc1_,_loc2_); streaks._rotation = (angle + 3.141592653589793) * 180 / 3.141592653589793; streaks.play(); return angle; } function aimPlayerGoal() { var _loc2_ = goalPlayer._x - ball._x; var _loc1_ = goalPlayer._y - ball._y; angle = Math.atan2(_loc1_,_loc2_); streaks._rotation = (angle + 3.141592653589793) * 180 / 3.141592653589793; streaks.play(); angle += Math.random() * 2 * PLAYERGOALRANDOM - PLAYERGOALRANDOM; return angle; } function aimPlayer(target) { var _loc2_ = target._x + players._x - ball._x; var _loc1_ = target._y + players._y - ball._y; angle = Math.atan2(_loc1_,_loc2_); streaks._rotation = (angle + 3.141592653589793) * 180 / 3.141592653589793; streaks.play(); stick2._rotation = angle * 180 / 3.141592653589793; return angle; } function collisions() { if(!colliding) { i = 0; while(i < rowsOpponent.length) { j = 0; while(j < rowsOpponent[i].length) { if(ball.hitTest(rowsOpponent[i][j].hit)) { Sound1.start(0,1); rowsOpponent[i][j].gotoAndPlay(2); ball.collideTimer = getTimer(); colliding = true; if(i == 0) { ballAngle = aimOpponentGoal(); ballAngle += Math.random() * ACCURACY - ACCURACY; ball.vx = Math.cos(ballAngle) * VMAXOPPONENT; ball.vy = Math.sin(ballAngle) * VMAXOPPONENT; ball.dw = 2 * ballAngle / 3.141592653589793; return true; } row = i - 1; player = rand(rowsOpponent[row].length - 1); mc = rowsOpponent[row][player]; ballAngle = aimOpponent(mc); ballAngle += Math.random() * ACCURACY - ACCURACY; ball.vx = Math.cos(ballAngle) * VMAXOPPONENT; ball.vy = Math.sin(ballAngle) * VMAXOPPONENT; ball.dw = 2 * ballAngle / 3.141592653589793; ball._x += ball.vx; ball._y += ball.vy; return true; } j++; } i++; } } return false; } function collisionsPlayer() { if(!colliding) { i = 0; while(i < rowsPlayer.length) { j = 0; while(j < rowsPlayer[i].length) { if(ball.hitTest(rowsPlayer[i][j].hit)) { rowsPlayer[i][j].gotoAndPlay(2); Sound1.start(0,1); ball.collideTimer = getTimer(); colliding = true; if(i == 0) { ballAngle = aimPlayerGoal(); ball.vx = Math.cos(ballAngle) * VMAX; ball.vy = Math.sin(ballAngle) * VMAX; ball.dw = 2 * ballAngle / 3.141592653589793; return true; } row = i - 1; player = rand(rowsPlayer[row].length - 1); mc = rowsPlayer[row][player]; ballAngle = aimPlayer(mc); ball.vx = Math.cos(ballAngle) * VMAX; ball.vy = Math.sin(ballAngle) * VMAX; ball.dw = 2 * ballAngle / 3.141592653589793; ball._x += ball.vx; ball._y += ball.vy; return true; } j++; } i++; } } return false; } MovieClip.prototype.rand = function(num) { if(arguments.length == 1) { return Math.floor(Math.random() * num) + 1; } return Math.floor(Math.random() * (Math.abs(arguments[1] - num) + 1)) + Math.min(num,arguments[1]); }; Sound1 = new Sound(); Sound1.attachSound("soccer_01"); Sound1.setVolume(10); GAME_ANGLE = 0; BALL_DIAMETER = 12; BALL_RADIUS = BALL_DIAMETER / 2; TOP = table_mc._y + BALL_RADIUS; BOTTOM = table_mc._y + table_mc._height - BALL_RADIUS; LEFT = table_mc._x + BALL_RADIUS; RIGHT = table_mc._x + table_mc._width - BALL_RADIUS; BOUNCE = -1; DAMP = 1; MINSPEED = 1; var playersLeftBoundary = 120; var playersRightBoundary = 240; var opponentsLeftBoundary = 10; var opponentsRightBoundary = 140; var scorePlayer = 0; var scoreOpponent = 0; var deg2rad = 0.017453292519943295; var colliding = false; var collideTime = 100; var winningScore = 5; ball._visible = false; goalPaddle._visible = false; goalCyclone._visible = false; trace(_global.player); if(_global.player == "paddle") { VMAX = 6; VMAXOPPONENT = 5; ACCURACY = 30 * deg2rad; MOVERATE = 3; OPPONENTMOVERATE = 1.5; PLAYERGOALRANDOM = 10 * deg2rad; opponents.gotoAndPlay("cyclone"); players.gotoAndPlay("paddle"); scoreBoardOpponent.logo.gotoAndPlay("cyclone"); scoreBoardPlayer.logo.gotoAndPlay("paddle"); opponentsGoalDisplay = goalCyclone; playersGoalDisplay = goalPaddle; } else { VMAX = 5; VMAXOPPONENT = 6; ACCURACY = 10 * deg2rad; MOVERATE = 3; OPPONENTMOVERATE = 1; PLAYERGOALRANDOM = 10 * deg2rad; opponents.gotoAndPlay("paddle"); players.gotoAndPlay("cyclone"); scoreBoardOpponent.logo.gotoAndPlay("paddle"); scoreBoardPlayer.logo.gotoAndPlay("cyclone"); opponentsGoalDisplay = goalPaddle; playersGoalDisplay = goalCyclone; } scoreBoardOpponent.slide(0,restart); scoreBoardPlayer.slide(400); Color.prototype.reduceRGB = function(p) { var _loc2_ = this.getTransform(); var _loc3_ = (100 - p) / 100; this.setTransform({ra:p,rb:_loc2_.rb * _loc3_,ga:p,gb:_loc2_.gb * _loc3_,ba:p,bb:_loc2_.bb * _loc3_}); }; Color.prototype.tintRGB = function(hex, p) { this.setRGB(hex); this.reduceRGB(p); }; var rowsOpponent = [[opponents.ball0,opponents.ball1,opponents.ball2],[opponents.ball3,opponents.ball4,opponents.ball6,opponents.ball7],[opponents.ball8,opponents.ball9],[opponents.ball10]]; var rowsPlayer = [[players.ball0,players.ball1,players.ball2],[players.ball3,players.ball4,players.ball6,players.ball7],[players.ball8,players.ball9],[players.ball10]]; trace(scoreOpponent); scoreBoardOpponent.setScore(1); stop();